<?php
	session_start();
	if(isset($_POST['name'])) {
		include_once('core/init.php');
		include_once('core/usersModel.php');
		
		$model = new UsersModel();
		$ok    = $model->checkLogin($_POST['name'], $_POST['password']);
		if($ok) {
			$_SESSION['loggedIn'] = true;
			header('Location: index.php');
		} else {
			// Security: wait 3 seconds on a login failure:
			sleep(3);
		}
	}
?>
<html>
	<head>
		<title>DataStruct v0.1 Beta</title>		
		<link rel="stylesheet" type="text/css" href="css/screen.css" />
		<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
		<script type="text/javascript" src="js/global.js"></script>
	</head>
	
	<body>
		<div id="body">
			<h1>Login</h1>
			<form method="post" action="login.php">
				<div>
					<label for="name">Username:</label>
					<input type="text" name="name" id="name" class="text" />
				</div>
				<div>
					<label for="password">Password:</label>
					<input type="password" name="password" id="password" class="text" />
				</div>
				<label>&nbsp;</label>
				<input type="submit" value="Login" class="submit" />
			</form>
		</div>
	</body>
</html>
